package com.godpaper.as9.util
{
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.controls.TextInput;
	import mx.managers.ToolTipManager;
	public class ShowErrorTooltipImmidiately
	{
		
		public static function display(fromObject:Object,alterBackgroundColor:uint=0xff5715,alterConfirm:Boolean=true):void
		{	
			fromObject.setFocus();
			fromObject.dispatchEvent(new FocusEvent(FocusEvent.FOCUS_IN));
			fromObject.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
			
			var timer:Timer = new Timer(5000, 1);
			
			timer.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent):void{ hideMyToolTip(fromObject); });
			timer.start();			
			
			//setInterval(hideToolTip, 3000, fromObject);
			
			//AlertBackgroundColor: should use error skin, this can't reset to original color
			if(alterConfirm)
			{
				//fromObject.setStyle("backgroundColor",alterBackgroundColor);
			}
			
			fromObject.addEventListener(FocusEvent.FOCUS_OUT,function(event:FocusEvent):void{
				hideMyToolTip(fromObject);				
			});	
			
			
		}
		
		private static function hideMyToolTip(fromObject:Object):void
		{
			if(ToolTipManager.currentTarget == fromObject && ToolTipManager.currentToolTip !=null)
			{
				ToolTipManager.currentToolTip.visible = false;
			}			
		}
		
		
	}
}